﻿@using Lari.Services.Data;
@using Lari.Configuration;
@model List<Role>
@{
    var id = ViewBag.id as int?;
    var pageNum = ViewBag.page as int?;

    var routDic = new RouteValueDictionary();

    if (pageNum.HasValue)
    {
        routDic.Add("page", pageNum.Value);
    }
        
}
@{
    var grid = new WebGrid(source: Model, rowsPerPage: ApplicationConfig.RowPerPage,
    canPage: true, canSort: true, defaultSort: "Name");
    grid.Pager(WebGridPagerModes.All);
    
    
}

<div id="pagetitle">
    <h1>@ScreenName.Users.Role</h1>
</div>
<div class="spacer">
</div>
<div id="pagecontent">
    <table style="border-collapse: collapse; width: 100%">
        <tr>
            <td id="leftColumn" style="width: 50%">
                <div id="grid">
                    @grid.GetHtml(
                        tableStyle: "webgrid",
                        headerStyle: "webgrid-header",
                        footerStyle: "webgrid-footer",
                        alternatingRowStyle: "webgrid-alternating-row",
                        selectedRowStyle: "webgrid-selected-row",
                        rowStyle: "webgrid-row-style",
                        columns: grid.Columns(grid.Column("Name", "All Role"),
                                              grid.Column(format: item => Html.ActionLink(GuiActionName.Modify, ActionConst.Users.EditRole, new { id = item.Id })),
                                              grid.Column(format: item =>
                                                                      {
                                                                          if (routDic.ContainsKey("id"))
                                                                          {
                                                                              routDic["id"] = item.Id;
                                                                          }
                                                                          else
                                                                          {
                                                                              routDic.Add("id", item.Id);
                                                                          }

                                                                          return Html.ActionLink(GuiActionName.View, ActionConst.Users.RoleList, routDic);
                                                                      })
                            )
           )
                </div>
                <div class="doubleSpacer">
                </div>
                <div>
                    @Html.ActionLink(ScreenName.Users.NewRole, ActionConst.Users.NewRole)
                </div>
                <div class="spacer">
                </div>
            </td>
            <td id="centerColumn">
                @if (id.HasValue && id.Value > 0)
                {
                    @Html.Action(ActionConst.Users.ViewRole, ControllerConst.Users, new { id = id.Value })
                }
            </td>
        </tr>
    </table>
</div>

